package com.sgb.kjwl.view.ui.adapter.machine;

import android.content.Context;
import android.graphics.Color;
import android.renderscript.ScriptGroup;
import android.text.TextUtils;
import android.view.View;

import com.sdk.mobile.manager.login.NoDoubleClickListener;
import com.sgb.kjwl.BR;
import com.sgb.kjwl.R;
import com.sgb.kjwl.databinding.ItemLeaseDemandBinding;
import com.sgb.kjwl.model.entity.lease.LeaseDemandListEntity;
import com.swgk.core.dialog.CommonDialog;
import com.swgk.core.recyclerview.adapter.BaseRecycleAdapter;
import com.swgk.core.recyclerview.adapter.ItemViewHolder;
import com.swgk.core.util.DateUtils;

import java.util.List;

/**
 * 租赁-快捷需求
 */
public class LeaseDemandAdapter extends BaseRecycleAdapter<LeaseDemandListEntity> {

    public LeaseDemandAdapter(Context context) {
        super(context, R.layout.item_lease_demand, null);
    }

    @Override
    public void convert(ItemViewHolder holder, LeaseDemandListEntity entity) {
        holder.setBinding(BR.viewModel, entity);
        ItemLeaseDemandBinding binding = (ItemLeaseDemandBinding) holder.getmBinding();

        if (!TextUtils.isEmpty(entity.getContactName())) {
            binding.tvContactName.setText(entity.getContactName());
        }

        try {
            binding.tvTime.setText(DateUtils.stampToDate(entity.getCreateTime()));
        } catch (Exception e) {
        }

        //状态(0:待处理,1处理中,2:已结束)
        if ("1".equals(entity.getStatus())) {
            binding.tvState.setText("处理中");
            binding.tvState.setTextColor(Color.parseColor("#06C764"));
        } else if ("2".equals(entity.getStatus())) {
            binding.tvState.setText("已结束");
            binding.tvState.setTextColor(Color.parseColor("#969696"));
        } else {
            binding.tvState.setText("待处理");
            binding.tvState.setTextColor(Color.parseColor("#FF4B10"));
        }

        binding.tvDel.setOnClickListener(new NoDoubleClickListener() {
            @Override
            public void onNoDoubleClick(View view) {
                if (listener != null) {
                    listener.onDel(entity.getNo());
                }
            }
        });

    }

    public interface OnCallBlackListener {
        void onDel(String no);
    }

    private OnCallBlackListener listener;

    public void setOnCallBlackListener(OnCallBlackListener listener) {
        this.listener = listener;
    }
}
